﻿using XKJ.OAWeb.EFCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XKJ.OAWeb.Models;
using System.Data;
using Dommel;
using System.Security.Cryptography;
using XKJ.OAWeb.Shared;
using Dapper;

namespace XKJ.OAWeb.Infrastructrue
{
    public class BaseRepository<T> : IBaseRepository<T> where T : class
    {
        protected IDbConnection _db = Dapper.GetInstance().GetDbConnection();
        //添加
        public int Add(T entity)
        {
            return Convert.ToInt32(_db.Insert(entity));
        }
        //反填
        public T Backfill(int Id)
        {
            return _db.Get<T>(Id);
        }
        //删除
        public bool Delete(T entity)
        {
            return _db.Delete(entity);
        }
        //删除指定Id
        public bool DeleteId(int Id)
        {
            return Delete(_db.Get<T>(Id));
        }
        //查询
        public IQueryable<T> Show()
        {
            return _db.GetAll<T>().AsQueryable();
        }
        //修改
        public int Uptdate(T entity)
        {
            return Convert.ToInt32(_db.Update(entity));
        }
    }
}
